﻿/*
 * 文件名称：
 * 程序员：wangyun
 * 创建时间：2008/05/27
 * 
 * 功能说明：功能模块的字段类型控件，日期和时间控件
 * 
 * 修改人员：yylu
 * 
 * 修改日期：2009/08/20
 * 
 * 修改记录：1)增加控件手写单独使用的代码
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common.WebHelper;

public partial class UserControls_FieldControl_DateTimeType : Whir.Controls.ModelField.BaseFieldControl
{
    public string dateFormat = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        Whir.BLL.Whir_FieldDateText bll = new Whir.BLL.Whir_FieldDateText();
        int fieldTextId = int.Parse(bll.GetList(" FieldID = " + this.FieldID).Tables[0].Rows[0][0].ToString());        
        string defaultValue = bll.GetModel(fieldTextId).defaultValue;

        if (this.isSingleUse)
        {
            this.InitFieldControl(this.FieldID);
        }

        if (!IsPostBack)
        {
            int ItemID = NetRequest.GetQueryInt("ItemID");
            if (ItemID == 0)
            {
                switch (bll.GetModel(fieldTextId).dateFormat)
                {
                    case 0:
                        dateFormat = "yyyy-MM-dd";
                        break;
                    case 1:
                        dateFormat = "yyyy-MM-dd HH:mm:ss";
                        break;
                }
                //添加操作，绑定默认值
                switch (defaultValue)
                {
                    case "0":
                        this.ezDateTimeType.Text = "";
                        break;
                    case "1":
                        this.ezDateTimeType.Text = DateTime.Now.ToString(dateFormat);                        
                        break;
                    default:
                        if (!string.IsNullOrEmpty(defaultValue))
                        {
                            this.ezDateTimeType.Text = Convert.ToDateTime(defaultValue).ToString(dateFormat);
                        }
                        else
                        {
                            this.ezDateTimeType.Text = DateTime.Now.ToString(dateFormat);
                        }
                        break;
                }

            }
            else
            {
                //更新操作，绑定值
                switch (bll.GetModel(fieldTextId).dateFormat)
                {
                    case 0:
                        dateFormat = "yyyy-MM-dd";
                        break;
                    case 1:
                        dateFormat = "yyyy-MM-dd HH:mm:ss";
                        break;
                }
                //添加操作，绑定默认值
                switch (defaultValue)
                {
                    case "0":
                        this.ezDateTimeType.Text = FieldCommon.GetBindValue(this.FieldID, ItemID);
                        break;
                    case "1":
                        this.ezDateTimeType.Text = DateTime.Now.ToString(dateFormat);
                        break;
                    default:
                        this.ezDateTimeType.Text = Convert.ToDateTime(FieldCommon.GetBindValue(this.FieldID, ItemID)).ToString(dateFormat);
                        break;
                }                
            }
            this.rfvDateTimeType.IsValid = this.EnableNull;     //设置验证控件是否验证颜色的值
            
        }
        else
        {
            this.FieldValue = this.ezDateTimeType.Text;
        }
    }
}
